package org.summer.generator.log;

import java.net.CacheRequest;
import java.time.LocalDateTime;

// 默认日志实现类
public class DefaultLogger implements Logger{
    private final Class<?> target;
    public DefaultLogger(Class<?> target){
        this.target = target;
    }

    private String getReaString(String context){
        return ANSI_RED + context + ANSI_END;
    }

    private String getGreenString(String context){
        return ANSI_GREEN + context + ANSI_END;
    }

    private String getCurrentTime(){
        return LocalDateTime.now().format(FORMATTER);
    }

    @Override
    public void debug(String msg, Object... args) {
        System.out.print(getGreenString(getCurrentTime()));
        System.out.print(" " + getGreenString(DEBUG));
        System.out.print(" " + getGreenString(target.getName()) + ": " + msg);
        if (args.length != 0){
            System.out.print(args);
        }
        System.out.println();
    }

    @Override
    public void error(String msg, Object ...args) {
        System.out.print(getReaString(getCurrentTime()));
        System.out.print(" " + getReaString(ERROR));
        System.out.print(" " + getReaString(target.getName()) + ": " + msg);
        if (args.length != 0){
            for (Object e: args){
                System.out.print(e);
            }
        }
        System.out.println();
    }


}
